package app.netant.galgame.sadbrother;

import org.jsoup.select.Elements;

import app.netant.NetAntBase;
import cn.lily.com.db.container.reader.DataTable;
import cn.lily.com.enviroment.Enviroment;
import cn.lily.com.lang.number.MathUtil;
/**
 * 忧郁的弟弟 - 分页爬取类
 * @author JiaJ
 * @date 2018年6月12日
 *
 */
public class SadBrotherAntPage extends NetAntBase {
	
	public SadBrotherAntPage(String netSite, int timeout) {
		super(netSite, timeout);
	}
	
	public SadBrotherAntPage(String netSite) {
		super(netSite);
	}
	
	/**
	 * 处理全部链接列表
	 */
	public void analyseLinkList(){
		
		Elements activePart = document.select("#zan-bodyer #mainstay #article-list .article.well .hidden-xs .title-article a");
		for(int i=0;i<activePart.size();i++){
			
			Enviroment.getEnv().getLogBean().beginLog();
			
			String detialHref = activePart.get(i).attr("href");
			
			System.out.println(detialHref+":开始连接....");
			
			DataTable dataTable = this.getDBManager().executeQueryTable("select * from ${schema}.LEO_SAD_BROTHER_INFO where LEO_SITE_ANALYSE='"+detialHref+"'");
			if(dataTable.next()){
				continue;
			}
					
			try {		
				//明细
				SadBrotherAntDetail detail = new SadBrotherAntDetail(activePart.get(i).attr("href"));			
				detail.analyse();
			} catch (Exception e) {			

				this.getDBManager().executeUpdate("insert into ${schema}.LEO_SAD_BROTHER_EXCEP (EXCEP_ID,EXCEP_URL,EXCEP_LEVEL) "
						                        + "values ('"+System.currentTimeMillis()+""+MathUtil.random(3)+"','"+detialHref+"','2') ");			
				continue;
			} finally {
				Enviroment.getEnv().getLogBean().endLog();
			}
			
		}
		
	}
	
	public static void main(String[] args) {
		SadBrotherAntPage page = new SadBrotherAntPage("https://www.mygalgame.com/page/2/");
		page.analyseLinkList();
	}
	
}
